package cn.itsource.util;

public class AjaxResult<T> {
        // 响应状态码
        private Integer code;

        // 操作结果
        private Boolean success;

        // 提示语
        private String msg;

        // 响应数据
        private T data;

        public static <T> AjaxResult<T> ok() {
            return new AjaxResult<T>(200, true, "操作成功", null);
        }

        public static <T> AjaxResult<T> ok(T data) {
            return new AjaxResult<T>(200, true, "操作成功", data);
        }

        public static <T> AjaxResult<T> ok(String message) {
            return new AjaxResult<T>(200, true, message, null);
        }

        public static <T> AjaxResult<T> ok(String message, T data) {
            return new AjaxResult<T>(200, true, message, data);
        }


        public static <T> AjaxResult<T> fail() {
            return new AjaxResult<T>(500, false, "操作失败！", null);
        }

        public static <T> AjaxResult<T> fail(T data) {
            return new AjaxResult<T>(500, false, "操作失败！", data);
        }

        public static <T> AjaxResult<T> fail(String message) {
            return new AjaxResult<T>(500, false, message, null);
        }

        public static <T> AjaxResult<T> fail(Integer code) {
            return new AjaxResult<T>(code, false, "操作失败！", null);
        }

        public static <T> AjaxResult<T> fail(String message, T data) {
            return new AjaxResult<T>(500, false, message, data);
        }

        public static <T> AjaxResult<T> fail(Integer code, T data) {
            return new AjaxResult<T>(code, false, "操作失败！", data);
        }

        public static <T> AjaxResult<T> fail(Integer code, String message) {
            return new AjaxResult<T>(code, false, message, null);
        }

        public static <T> AjaxResult<T> fail(Integer code, String message, T data) {
            return new AjaxResult<T>(code, false, message, data);
        }


        public AjaxResult(Integer code, Boolean success, String msg, T data) {
            this.code = code;
            this.msg = msg;
            this.success = success;
            this.data = data;
        }

        public Integer getCode() {
            return code;
        }

        public void setCode(Integer code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        public Boolean getSuccess() {
            return success;
        }

        public void setSuccess(Boolean success) {
            this.success = success;
        }

        public T getData() {
            return data;
        }

        public void setData(T data) {
            this.data = data;
        }

}
